package com.authine.cloudpivot.web.api.controller;

import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.service.PortalService;
import com.authine.cloudpivot.web.api.service.ReportService;
import io.swagger.annotations.ApiOperation;
import jodd.util.CollectionUtil;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Stream;

/**
 * @description:
 * @author: zyj
 * @time: 2022/2/16 13:46
 */
@RestController
@RequestMapping("/api/customReport")
@Slf4j
public class CustomReportController extends BaseController {

    @Autowired
    private ReportService reportService;

    @Value("${customPortal.sheetPowerUrl}")
    private String sheetPowerUrl;

    @Value("${report.opGpDeptAll:RCS}")
    private String opGpDeptAll;


    @Autowired
    private PortalService portalService;

    /**
     * 服务类型报表
     * @param
     * @return
     */
    @ApiOperation(value = "服务类型报表" )
    @GetMapping("/serviceType")
    @ResponseBody
    public Map<String, Object> serviceType(){
        List<Map<String, Object>> list = reportService.serviceType();
        list.sort(Comparator.comparingInt(s -> MapUtils.getInteger(s,"sort")));
        Map<String, Object> reportData = new HashMap<>();
        List<Map<String, Object>> subjectA = new ArrayList<>();
        List<Map<String, Object>> subjectB = new ArrayList<>();
        Integer qtCount = 0;
        Integer jcrsfwCount = 0;
        Integer lhygCount = 0;
        Integer yxywwbCount = 0;
        if(!CollectionUtils.isEmpty(list)){
            for (Map<String, Object> map : list) {
                Integer count = MapUtils.getInteger(map, "count");
                String sumType = MapUtils.getString(map, "sumType");
                switch (sumType){
                    case "营销业务外包":
                        yxywwbCount += count;
                        break;
                    case "灵活用工":
                        lhygCount += count;
                        break;
                    case "其他":
                        qtCount += count;
                        break;
                    case "基础人事服务":
                        jcrsfwCount += count;
                        break;
                    default:
                        continue;
                }
            }
            Map<String, Object> map1 = new HashMap<>();
            Map<String, Object> map2 = new HashMap<>();
            Map<String, Object> map3 = new HashMap<>();
            Map<String, Object> map4 = new HashMap<>();
            map1.put("value",yxywwbCount);
            map1.put("name","营销业务外包");
            map2.put("value",lhygCount);
            map2.put("name","灵活用工");
            map3.put("value",qtCount);
            map3.put("name","其他");
            map4.put("value",jcrsfwCount);
            map4.put("name","基础人事服务");
            subjectA.add(map1);
            subjectA.add(map2);
            subjectA.add(map3);
            subjectA.add(map4);
            for (Map<String, Object> map : list) {
                String type = MapUtils.getString(map, "type");
                Integer count = MapUtils.getInteger(map, "count");
                Map<String, Object> maps = new HashMap<>();
                maps.put("name",type);
                maps.put("value",count);
                subjectB.add(maps);
            }
        }
        reportData.put("项目大类",subjectA);
        reportData.put("项目子类",subjectB);

        Map<String, String> parentMap = portalService.getParentId("XMQD");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XMQD");
        reportData.put("url",url);
        return reportData;
    }

    @ApiOperation(value = "获取gpop日期" )
    @GetMapping("/getGpOpDate")
    @ResponseBody
    public String getGpOpDate(){
        String date = reportService.getLastGpOpDate();
        return date;
    }

    @ApiOperation(value = "获取gpop部门" )
    @GetMapping("/getGpOpDepartment")
    @ResponseBody
    public List<String> getGpOpDepartment(String date){
        List<String> deps = reportService.getGpOpDepartment(date);
        return deps;
    }

    @ApiOperation(value = "op数据" )
    @GetMapping("/opTrend")
    @ResponseBody
    public List<Map<String, Object>> opTrend(String dateStr,String department){
        if(StringUtil.isBlank(dateStr)){
            dateStr = reportService.getLastGpOpDate();
        }
        if (StringUtil.isEmpty(department)) {
            department=opGpDeptAll;
        }

        String nowYear = LocalDateTime.now().minusMonths(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        String beforYear = LocalDateTime.now().minusMonths(1).minusYears(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        List<Map<String, Object>> list = reportService.opTrend(dateStr,department);
        List<Map<String, Object>> returnList = new ArrayList<>();
        Map<String,Map<String, Object>> maps = new HashMap<>();
        for (Map<String, Object> map : list) {
            maps.put(MapUtils.getString(map,"month"),map);
        }
        List<String> yearMonth = getYearMonth();
        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> line2 = new HashMap<>();
        Map<String, Object> line3 = new HashMap<>();
        Map<String, Object> line4 = new HashMap<>();
        Map<String, Object> line5 = new HashMap<>();
        List<String> data1 = new ArrayList<>();
        List<String> data2 = new ArrayList<>();
        List<String> data3 = new ArrayList<>();
        List<String> data4 = new ArrayList<>();
        List<String> data5 = new ArrayList<>();
        if(!CollectionUtils.isEmpty(list)){
            for (String month : yearMonth) {
                Map<String, Object> map = maps.get(month);
                Object beforeActual = map.get("beforeActual");
                Object nowActual = map.get("nowActual");
                Object forecast = map.get("forecast");
                Object budget = map.get("budget");
                Object op = map.get("op");
                data1.add(beforeActual == null ? "" : beforeActual.toString());
                data2.add(nowActual == null ? "" : nowActual.toString());
                data3.add(forecast == null ? "" : forecast.toString());
                data4.add(budget == null ? "" : budget.toString());
                data5.add(op == null ? "" : op.toString());
            }
        }
        line1.put("name",beforYear.concat("Actual"));
        line2.put("name",nowYear.concat("Actual"));
        line3.put("name",nowYear.concat("Forecast"));
        line4.put("name",nowYear.concat("Budget"));
        line5.put("name","OP%");
        line1.put("type","line");
        line2.put("type","line");
        line3.put("type","line");
        line4.put("type","line");
        line5.put("type","line");
        line1.put("yAxisIndex",0);
        line2.put("yAxisIndex",0);
        line3.put("yAxisIndex",0);
        line4.put("yAxisIndex",0);
        line5.put("yAxisIndex",1);
        line1.put("data",data1);
        line2.put("data",data2);
        line3.put("data",data3);
        line4.put("data",data4);
        line5.put("data",data5);
        line1.put("symbol","none");
        line2.put("symbol","none");
        line3.put("symbol","none");
        line4.put("symbol","none");
        returnList.add(line1);
        returnList.add(line2);
        returnList.add(line3);
        returnList.add(line4);
        returnList.add(line5);
        return returnList;
    }

    @ApiOperation(value = "gp数据" )
    @GetMapping("/gpTrend")
    @ResponseBody
    public List<Map<String, Object>> gpTrend(String dateStr,String department){
        if(StringUtil.isBlank(dateStr)){
            dateStr = reportService.getLastGpOpDate();
        }
        if (StringUtil.isEmpty(department)) {
            department=opGpDeptAll;
        }
        String nowYear = LocalDateTime.now().minusMonths(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        String beforYear = LocalDateTime.now().minusMonths(1).minusYears(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        List<Map<String, Object>> list = reportService.gpTrend(dateStr,department);
        List<Map<String, Object>> returnList = new ArrayList<>();
        Map<String,Map<String, Object>> maps = new HashMap<>();
        for (Map<String, Object> map : list) {
            maps.put(MapUtils.getString(map,"month"),map);
        }
        List<String> yearMonth = getYearMonth();
        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> line2 = new HashMap<>();
        Map<String, Object> line3 = new HashMap<>();
        Map<String, Object> line4 = new HashMap<>();
        Map<String, Object> line5 = new HashMap<>();
        List<String> data1 = new ArrayList<>();
        List<String> data2 = new ArrayList<>();
        List<String> data3 = new ArrayList<>();
        List<String> data4 = new ArrayList<>();
        List<String> data5 = new ArrayList<>();
        if(!CollectionUtils.isEmpty(list)){
            for (String month : yearMonth) {
                Map<String, Object> map = maps.get(month);
                Object beforeActual = map.get("beforeActual");
                Object nowActual = map.get("nowActual");
                Object forecast = map.get("forecast");
                Object budget = map.get("budget");
                Object gp = map.get("gp");
                data1.add(beforeActual == null ? "" : beforeActual.toString());
                data2.add(nowActual == null ? "" : nowActual.toString());
                data3.add(forecast == null ? "" : forecast.toString());
                data4.add(budget == null ? "" : budget.toString());
                data5.add(gp == null ? "" : gp.toString());
            }
        }
        line1.put("name",beforYear.concat("Actual"));
        line2.put("name",nowYear.concat("Actual"));
        line3.put("name",nowYear.concat("Forecast"));
        line4.put("name",nowYear.concat("Budget"));
        line5.put("name","GP%");
        line1.put("type","line");
        line2.put("type","line");
        line3.put("type","line");
        line4.put("type","line");
        line5.put("type","line");
        line1.put("yAxisIndex",0);
        line2.put("yAxisIndex",0);
        line3.put("yAxisIndex",0);
        line4.put("yAxisIndex",0);
        line5.put("yAxisIndex",1);
        line1.put("data",data1);
        line2.put("data",data2);
        line3.put("data",data3);
        line4.put("data",data4);
        line5.put("data",data5);
        line1.put("symbol","none");
        line2.put("symbol","none");
        line3.put("symbol","none");
        line4.put("symbol","none");
        returnList.add(line1);
        returnList.add(line2);
        returnList.add(line3);
        returnList.add(line4);
        returnList.add(line5);
        return returnList;
    }

    @ApiOperation(value = "rev数据" )
    @GetMapping("/revTrend")
    @ResponseBody
    public List<Map<String, Object>> revTrend(String dateStr,String department){
        if(StringUtil.isBlank(dateStr)){
            dateStr = reportService.getLastGpOpDate();
        }
        if (StringUtil.isEmpty(department)) {
            department=opGpDeptAll;
        }
        String nowYear = LocalDateTime.now().minusMonths(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        String beforYear = LocalDateTime.now().minusMonths(1).minusYears(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        List<Map<String, Object>> list = reportService.revTrend(dateStr,department);
        List<Map<String, Object>> returnList = new ArrayList<>();
        Map<String,Map<String, Object>> maps = new HashMap<>();
        for (Map<String, Object> map : list) {
            maps.put(MapUtils.getString(map,"month"),map);
        }
        List<String> yearMonth = getYearMonth();
        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> line2 = new HashMap<>();
        Map<String, Object> line3 = new HashMap<>();
        Map<String, Object> line4 = new HashMap<>();
        List<String> data1 = new ArrayList<>();
        List<String> data2 = new ArrayList<>();
        List<String> data3 = new ArrayList<>();
        List<String> data4 = new ArrayList<>();
        if(!CollectionUtils.isEmpty(list)){
            for (String month : yearMonth) {
                Map<String, Object> map = maps.get(month);
                Object beforeActual = map.get("beforeActual");
                Object nowActual = map.get("nowActual");
                Object forecast = map.get("forecast");
                Object budget = map.get("budget");
                data1.add(beforeActual == null ? "" : beforeActual.toString());
                data2.add(nowActual == null ? "" : nowActual.toString());
                data3.add(forecast == null ? "" : forecast.toString());
                data4.add(budget == null ? "" : budget.toString());
            }
        }
        line1.put("name",beforYear.concat("Actual"));
        line2.put("name",nowYear.concat("Actual"));
        line3.put("name",nowYear.concat("Forecast"));
        line4.put("name",nowYear.concat("Budget"));
        line1.put("type","line");
        line2.put("type","line");
        line3.put("type","line");
        line4.put("type","line");
        line1.put("data",data1);
        line2.put("data",data2);
        line3.put("data",data3);
        line4.put("data",data4);
        line1.put("symbol","none");
        line2.put("symbol","none");
        line3.put("symbol","none");
        line4.put("symbol","none");
        returnList.add(line1);
        returnList.add(line2);
        returnList.add(line3);
        returnList.add(line4);
        return returnList;
    }

    @ApiOperation(value = "sga数据" )
    @GetMapping("/sgaTrend")
    @ResponseBody
    public List<Map<String, Object>> sgaTrend(String dateStr,String department){
        if(StringUtil.isBlank(dateStr)){
            dateStr = reportService.getLastGpOpDate();
        }
        if (StringUtil.isEmpty(department)) {
            department=opGpDeptAll;
        }
        String nowYear = LocalDateTime.now().minusMonths(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        String beforYear = LocalDateTime.now().minusMonths(1).minusYears(1).toLocalDate().format(DateTimeFormatter.ofPattern("yyyy"));
        List<Map<String, Object>> list = reportService.sgaTrend(dateStr,department);
        List<Map<String, Object>> returnList = new ArrayList<>();
        Map<String,Map<String, Object>> maps = new HashMap<>();
        for (Map<String, Object> map : list) {
            maps.put(MapUtils.getString(map,"month"),map);
        }
        List<String> yearMonth = getYearMonth();
        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> line2 = new HashMap<>();
        Map<String, Object> line3 = new HashMap<>();
        Map<String, Object> line4 = new HashMap<>();
        List<String> data1 = new ArrayList<>();
        List<String> data2 = new ArrayList<>();
        List<String> data3 = new ArrayList<>();
        List<String> data4 = new ArrayList<>();
        if(!CollectionUtils.isEmpty(list)){
            for (String month : yearMonth) {
                Map<String, Object> map = maps.get(month);
                Object beforeActual = map.get("beforeActual");
                Object nowActual = map.get("nowActual");
                Object forecast = map.get("forecast");
                Object budget = map.get("budget");
                data1.add(beforeActual == null ? "" : beforeActual.toString());
                data2.add(nowActual == null ? "" : nowActual.toString());
                data3.add(forecast == null ? "" : forecast.toString());
                data4.add(budget == null ? "" : budget.toString());
            }
        }
        line1.put("name",beforYear.concat("Actual"));
        line2.put("name",nowYear.concat("Actual"));
        line3.put("name",nowYear.concat("Forecast"));
        line4.put("name",nowYear.concat("Budget"));
        line1.put("type","line");
        line2.put("type","line");
        line3.put("type","line");
        line4.put("type","line");
        line1.put("data",data1);
        line2.put("data",data2);
        line3.put("data",data3);
        line4.put("data",data4);
        line1.put("symbol","none");
        line2.put("symbol","none");
        line3.put("symbol","none");
        line4.put("symbol","none");
        returnList.add(line1);
        returnList.add(line2);
        returnList.add(line3);
        returnList.add(line4);
        return returnList;
    }

    @ApiOperation(value = "项目新增流失数据" )
    @GetMapping("/subjectAdditionalLoss")
    @ResponseBody
    public Map<String, Object> subjectAdditionalLoss(String year) {
        Map<String, Object> returnMap = new HashMap<>();
        List<Map<String, Object>> returnList = new ArrayList<>();
        if(StringUtil.isBlank(year)){
            year = String.valueOf(LocalDateTime.now().getYear());
        }

        List<Map<String, Object>> listAdditional = reportService.subjectAdditional(year);
        Map<String, Map<String, Object>> mapsAdditional = new HashMap<>();
        if (!CollectionUtils.isEmpty(listAdditional)) {
            for (Map<String, Object> map : listAdditional) {
                mapsAdditional.put(MapUtils.getString(map, "month"), map);
            }
        }
        List<Map<String, Object>> listLoss = reportService.subjectLoss(year);
        Map<String, Map<String, Object>> mapsLoss = new HashMap<>();
        if (!CollectionUtils.isEmpty(listLoss)) {
            for (Map<String, Object> map : listLoss) {
                mapsLoss.put(MapUtils.getString(map, "month"), map);
            }
        }
        List<String> yearMonthInt = getYearMonthInt();
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        Map<String, Object> bar3 = new HashMap<>();
        Map<String, Object> bar4 = new HashMap<>();
        List<Object> list1 = new ArrayList<>();
        List<Object> list2 = new ArrayList<>();
        List<Object> list3 = new ArrayList<>();
        List<Object> list4 = new ArrayList<>();
        List<Object> details = new ArrayList<>();
        for (String month : yearMonthInt) {
            StringBuilder detail = new StringBuilder();
            Map<String, Object> mapA = mapsAdditional.get(month);
            Map<String, Object> mapL = mapsLoss.get(month);
            List<String> trueCountDetailA = reportService.subjectAdditionalDetail(year,getMonthValue(month),"是");
            List<String> falseCountDetailA = reportService.subjectAdditionalDetail(year,getMonthValue(month),"否");
            List<String> trueCountDetailL = reportService.subjectLossDetail(year,getMonthValue(month),"是");
            List<String> falseCountDetailL = reportService.subjectLossDetail(year,getMonthValue(month),"否");
            if(CollectionUtils.isEmpty(mapA)){
                list1.add(null);
                list2.add(null);
                detail.append("当月新增-有合同:  0").append("<br/>");
                detail.append("当月新增-无合同:  0").append("<br/>");
            }else{
                Integer trueCount = MapUtils.getInteger(mapA, "trueCount");
                Integer falseCount = MapUtils.getInteger(mapA, "falseCount");
                list1.add(trueCount == 0 ? null : trueCount);
                list2.add(falseCount == 0 ? null : falseCount);
                detail.append("当月新增-有合同:  ").append(trueCount).append("<br/>");
                if(!CollectionUtils.isEmpty(trueCountDetailA)){
                    detail.append(String.join("<br/>", trueCountDetailA)).append("<br/>");
                }
                detail.append("当月新增-无合同:  ").append(falseCount).append("<br/>");
                if(!CollectionUtils.isEmpty(falseCountDetailA)){
                    detail.append(String.join("<br/>", falseCountDetailA)).append("<br/>");
                }
            }
            if(CollectionUtils.isEmpty(mapL)){
                list3.add(null);
                list4.add(null);
                detail.append("当月流失-有合同:  0").append("<br/>");
                detail.append("当月流失-无合同:  0").append("<br/>");
            }else{
                Integer trueCount = 0 - Integer.valueOf(mapL.get("trueCount").toString());
                Integer falseCount = 0 - Integer.valueOf(mapL.get("falseCount").toString());
                list3.add(trueCount == 0 ? null : trueCount);
                list4.add(falseCount == 0 ? null : falseCount);
                detail.append("当月流失-有合同:  ").append(trueCount).append("<br/>");
                if(!CollectionUtils.isEmpty(trueCountDetailL)){
                    detail.append(String.join("<br/>", trueCountDetailL)).append("<br/>");
                }
                detail.append("当月流失-无合同:  ").append(falseCount).append("<br/>");
                if(!CollectionUtils.isEmpty(falseCountDetailL)){
                    detail.append(String.join("<br/>", falseCountDetailL)).append("<br/>");
                }
            }
            details.add(detail);
        }
        bar1.put("data",list1);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("name","当月新增-有合同");
        bar2.put("data",list2);
        bar2.put("type","bar");
        bar2.put("stack","stack");
        bar2.put("name","当月新增-无合同");
        bar3.put("data",list3);
        bar3.put("type","bar");
        bar3.put("stack","stack");
        bar3.put("name","当月流失-有合同");
        bar4.put("data",list4);
        bar4.put("type","bar");
        bar4.put("stack","stack");
        bar4.put("name","当月流失-无合同");
        returnList.add(bar1);
        returnList.add(bar2);
        returnList.add(bar3);
        returnList.add(bar4);
        returnMap.put("data",returnList);
        returnMap.put("details",details);
        Map<String, String> parentMap = portalService.getParentId("XMQD");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XMQD");
        returnMap.put("url",url);
        return returnMap;
    }

    @ApiOperation(value = "项目状态数据" )
    @GetMapping("/subjectStatus")
    @ResponseBody
    public Map<String, Object> subjectStatus(String year) {
        Map<String, Object> returnMap = new HashMap<>();
        List<Map<String, Object>> returnList = new ArrayList<>();
        if(StringUtil.isBlank(year)){
            year = String.valueOf(LocalDateTime.now().getYear());
        }

        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        List<Integer> list3 = new ArrayList<>();
        List<Integer> list4 = new ArrayList<>();
        List<Integer> list5 = new ArrayList<>();
        List<String> yearMonthInt = getYearMonthInt();
        Integer now = LocalDate.now().getMonthValue();
        Integer nowYear = LocalDate.now().getYear();
        boolean before = true;
        if(Integer.valueOf(year) < nowYear){
            before = false;
        }
        //计算预通告
        for (String month : yearMonthInt) {
            if(Integer.valueOf(month.substring(0,month.length()-1)) > now && before){
                list1.add(null);
                list2.add(null);
                list3.add(null);
                list4.add(null);
                list5.add(null);
            }else{
                //现有未立项计算预通告
                Integer c1 = reportService.ytgCount(getYearMonthValue(month,year));
                //现有立项计算立项
                Integer c2 = reportService.xmCount(getYearMonthValue(month,year));
                //现有项目关闭计算关闭
                Integer c3 = reportService.xmgbCount(getYearMonthValue(month,year));
                //预通告转项目
                Integer c4 = reportService.ytgxmCount(getYearMonthValue(month,year));
                //项目转关闭
                Integer c5 = reportService.xmxmgbCount(getYearMonthValue(month,year));
                //预提高转关闭
                Integer c6 = reportService.ytgxmgbCount(getYearMonthValue(month,year));
                list1.add(c1 == 0 ? null : c1);
                list2.add((c4 - c6) == 0 ? null : (c4 - c6));
                list3.add((c2 - c4) == 0 ? null : (c2 - c4));
                list4.add(c5 == 0 ? null : c5);
                list5.add((c3 - c5 - c6) == 0 ? null : (c3 - c5 - c6));
            }
        }
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        Map<String, Object> bar3 = new HashMap<>();
        Map<String, Object> bar4 = new HashMap<>();
        Map<String, Object> bar5 = new HashMap<>();

        bar1.put("data",list1);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("name","预通告");
        bar2.put("data",list2);
        bar2.put("type","bar");
        bar2.put("stack","stack");
        bar2.put("name","预通告+进行中");
        bar3.put("data",list3);
        bar3.put("type","bar");
        bar3.put("stack","stack");
        bar3.put("name","进行中");
        bar4.put("data",list4);
        bar4.put("type","bar");
        bar4.put("stack","stack");
        bar4.put("name","进行中+已结束");
        bar5.put("data",list5);
        bar5.put("type","bar");
        bar5.put("stack","stack");
        bar5.put("name","已结束");
        returnList.add(bar1);
        returnList.add(bar2);
        returnList.add(bar3);
        returnList.add(bar4);
        returnList.add(bar5);
        returnMap.put("data",returnList);
        Map<String, String> parentMap = portalService.getParentId("XMQD");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XMQD");
        returnMap.put("url",url);
        return returnMap;
    }

    @ApiOperation(value = "薪资人数-平均" )
    @GetMapping("/payPeopleCountingAvg")
    @ResponseBody
    public Map<String, Object> payPeopleCountingAvg(String time) throws ParseException {
        Date date = new Date();
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy");
        SimpleDateFormat df2 = new SimpleDateFormat("MM");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMM");
        SimpleDateFormat dfMonth = new SimpleDateFormat("M");
        if(StringUtil.isNotEmpty(time)){
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
            date = df.parse(time);
        }else{
            Date dt = new Date();
            Calendar rightNow = Calendar.getInstance();
            rightNow.setTime(dt);
            rightNow.add(Calendar.MONTH,-2);
            date = rightNow.getTime();
        }
        String beforeDate  = String.valueOf(Integer.valueOf(df1.format(date)) - 1).concat(df2.format(date));
        String month  = dfMonth.format(date);
        Map<String, Object> returnMap = new HashMap<>();
        List<Map<String, Object>> befor = reportService.getBeforYearData(beforeDate,month,String.valueOf(Integer.valueOf(df1.format(date)) - 1));
        List<Map<String, Object>> now = reportService.getNowYearData(dfString.format(date),month,df1.format(date));
        List<Map<String, Object>> pays = reportService.getNowYearDataAvgPay(dfString.format(date),df1.format(date));
        Map<String, Map<String, Object>> payPeopleCounting = createPayPeopleCountingAvg();
        if(!CollectionUtils.isEmpty(now)){
            Map<String, Object> nowMap = payPeopleCounting.get("now");
            for (Map<String, Object> map : now) {
                String typeb = MapUtils.getString(map,"typeb");
                Integer count = MapUtils.getInteger(map, "count");
                nowMap.put(typeb,count);
            }
        }
        if(!CollectionUtils.isEmpty(befor)){
            Map<String, Object> beforMap = payPeopleCounting.get("befor");
            for (Map<String, Object> map : befor) {
                String typeb = MapUtils.getString(map,"typeb");
                Integer count = MapUtils.getInteger(map, "count");
                beforMap.put(typeb,count);
            }
        }
        if(!CollectionUtils.isEmpty(pays)){
            Map<String, Object> payMap = payPeopleCounting.get("pay");
            for (Map<String, Object> map : pays) {
                String typeb = MapUtils.getString(map,"typeb");
                Integer pay = MapUtils.getInteger(map, "pay");
                payMap.put(typeb,pay);
            }
        }
        Map<String, Object> nowMap = payPeopleCounting.get("now");
        Map<String, Object> beforMap = payPeopleCounting.get("befor");
        Map<String, Object> payMap = payPeopleCounting.get("pay");
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        List<Object> list1 = new ArrayList<>();
        List<Object> list2 = new ArrayList<>();
        List<Object> list3 = new ArrayList<>();
        List<String> list4 = new ArrayList<>();
        for (String key : nowMap.keySet()) {
            list1.add(nowMap.get(key));
            list2.add(beforMap.get(key));
            if(key.contains("-")){
                list3.add("");
                list4.add("");
            }else{
                list3.add(key);
                Object pay = payMap.get(key);
                StringBuilder str = new StringBuilder();
                str.append(key).append("<br/>");
                str.append("去年MTD人数：").append(beforMap.get(key)).append("<br/>");
                str.append("当年MTD人数：").append(nowMap.get(key)).append("<br/>");
                str.append("当年MTD薪资：").append(pay==null?"":pay).append("元");
                list4.add(str.toString());
            }
        }
        bar1.put("data",list2);
        bar1.put("type","bar");
        bar1.put("stack","stack1");
        bar1.put("name","去年MTD人数");
        bar2.put("data",list1);
        bar2.put("type","bar");
        bar2.put("stack","stack2");
        bar2.put("name","当年MTD人数");
        returnMap.put("bar1",bar1);
        returnMap.put("bar2",bar2);
        returnMap.put("names",list3);
        returnMap.put("details",list4);
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月全职人员");
        String mon = format.format(date);
        returnMap.put("year",mon.concat(" MTD"));

        Map<String, String> parentMap = portalService.getParentId("pay");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","pay");
        returnMap.put("url",url);
        return returnMap;
    }

    @ApiOperation(value = "薪资人数-总和" )
    @GetMapping("/payPeopleCountingSum")
    @ResponseBody
    public Map<String, Object> payPeopleCountingSum(String time) throws ParseException {
        Date date = new Date();
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy");
        SimpleDateFormat df2 = new SimpleDateFormat("MM");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMM");
        if(StringUtil.isNotEmpty(time)){
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
            date = df.parse(time);
        }else{
            Date dt = new Date();
            Calendar rightNow = Calendar.getInstance();
            rightNow.setTime(dt);
            rightNow.add(Calendar.MONTH,-2);
            date = rightNow.getTime();
        }
        String beforeDate  = String.valueOf(Integer.valueOf(df1.format(date)) - 1).concat(df2.format(date));
        Map<String, Object> returnMap = new HashMap<>();
        List<Map<String, Object>> beforLhyg = reportService.getBeforYearSumDataLhyg(beforeDate,String.valueOf(Integer.valueOf(df1.format(date)) - 1));
        List<Map<String, Object>> nowLhyg = reportService.getNowYearSumDataLhyg(dfString.format(date),df1.format(date));
        Map<String, Map<String, Object>> payPeopleCounting = createPayPeopleCountingSum();
        if(!CollectionUtils.isEmpty(nowLhyg)){
            Map<String, Object> nowMap = payPeopleCounting.get("now");
            for (Map<String, Object> map : nowLhyg) {
                String typeb = MapUtils.getString(map,"typeb");
                Integer count = MapUtils.getInteger(map, "count");
                nowMap.put(typeb,count);
            }
        }
        if(!CollectionUtils.isEmpty(beforLhyg)){
            Map<String, Object> beforMap = payPeopleCounting.get("befor");
            for (Map<String, Object> map : beforLhyg) {
                String typeb = MapUtils.getString(map,"typeb");
                Integer count = MapUtils.getInteger(map, "count");
                beforMap.put(typeb,count);
            }
        }
        Map<String, Object> nowMap = payPeopleCounting.get("now");
        Map<String, Object> beforMap = payPeopleCounting.get("befor");
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        List<Object> list1 = new ArrayList<>();
        List<Object> list2 = new ArrayList<>();
        List<Object> list3 = new ArrayList<>();
        for (String key : nowMap.keySet()) {
            list1.add(nowMap.get(key));
            list2.add(beforMap.get(key));
            if(key.contains("-")){
                list3.add("");
            }else{
                list3.add(key);
            }
        }
        bar1.put("data",list2);
        bar1.put("type","bar");
        bar1.put("stack","stack1");
        bar1.put("name","去年YTD人数");
        bar2.put("data",list1);
        bar2.put("type","bar");
        bar2.put("stack","stack2");
        bar2.put("name","当年YTD人数");
        returnMap.put("bar1",bar1);
        returnMap.put("bar2",bar2);
        returnMap.put("names",list3);
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月兼职人员");
        String mon = format.format(date);
        returnMap.put("year",mon.concat(" YTD"));

        Map<String, String> parentMap = portalService.getParentId("pay");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","pay");
        returnMap.put("url",url);
        return returnMap;
    }

    @ApiOperation(value = "项目区域覆盖占比" )
    @GetMapping("/subjectCover")
    @ResponseBody
    public Map<String, List<Map<String, Object>>> subjectCover(){
        List<Map<String, Object>> list = reportService.subjectCover();
        Map<String, List<Map<String, Object>>> reportData = new HashMap<>();
        List<Map<String, Object>> subjectA = new ArrayList<>();
        List<Map<String, Object>> subjectB = new ArrayList<>();
        Integer hyg = 0;
        Integer hhq = 0;
        Integer hxx = 0;
        Integer hcl = 0;
        Integer hss = 0;
        Integer hyg1 = 0;
        Integer hhq1 = 0;
        Integer hxx1 = 0;
        Integer hcl1 = 0;
        Integer hss1 = 0;
        Integer hyg2 = 0;
        Integer hhq2 = 0;
        Integer hxx2 = 0;
        Integer hcl2 = 0;
        Integer hss2 = 0;
        Integer hyg3 = 0;
        Integer hhq3 = 0;
        Integer hxx3 = 0;
        Integer hcl3 = 0;
        Integer hss3 = 0;
        Integer hyg4 = 0;
        Integer hhq4 = 0;
        Integer hxx4 = 0;
        Integer hcl4 = 0;
        Integer hss4 = 0;
        if(!CollectionUtils.isEmpty(list)){
            for (Map<String, Object> map : list) {
                String rcsArea = MapUtils.getString(map, "rcsArea");
                String name = MapUtils.getString(map, "name");
                a: switch (name){
                    case "RCS慧用工":
                        hyg++;
                        switch (rcsArea){
                            case "东区":
                                hyg1++;
                                break a;
                            case "南区":
                                hyg2++;
                                break a;
                            case "西区":
                                hyg3++;
                                break a;
                            case "北区":
                                hyg4++;
                                break a;
                            default:
                                break a;
                        }
                    case "RCS慧韩企":
                        hhq++;
                        switch (rcsArea){
                            case "东区":
                                hhq1++;
                                break a;
                            case "南区":
                                hhq2++;
                                break a;
                            case "西区":
                                hhq3++;
                                break a;
                            case "北区":
                                hhq4++;
                                break a;
                            default:
                                break a;
                        }
                    case "RCS慧行销":
                        hxx++;
                        switch (rcsArea){
                            case "东区":
                                hxx1++;
                                break a;
                            case "南区":
                                hxx2++;
                                break a;
                            case "西区":
                                hxx3++;
                                break a;
                            case "北区":
                                hxx4++;
                                break a;
                            default:
                                break a;
                        }
                    case "RCS慧陈列":
                        hcl++;
                        switch (rcsArea){
                            case "东区":
                                hcl1++;
                                break a;
                            case "南区":
                                hcl2++;
                                break a;
                            case "西区":
                                hcl3++;
                                break a;
                            case "北区":
                                hcl4++;
                                break a;
                            default:
                                break a;
                        }
                    case "RCS慧时尚":
                        hss++;
                        switch (rcsArea){
                            case "东区":
                                hss1++;
                                break a;
                            case "南区":
                                hss2++;
                                break a;
                            case "西区":
                                hss3++;
                                break a;
                            case "北区":
                                hss4++;
                                break a;
                            default:
                                break a;
                        }
                    default:
                        continue;
                }
            }
            Map<String, Object> map1 = new HashMap<>();
            Map<String, Object> map2 = new HashMap<>();
            Map<String, Object> map3 = new HashMap<>();
            Map<String, Object> map4 = new HashMap<>();
            Map<String, Object> map5 = new HashMap<>();
            map1.put("value",hyg);
            map1.put("name","慧用工");
            map2.put("value",hhq);
            map2.put("name","慧韩企");
            map3.put("value",hxx);
            map3.put("name","慧行销");
            map4.put("value",hcl);
            map4.put("name","慧陈列");
            map5.put("value",hss);
            map5.put("name","慧时尚");
            subjectA.add(map1);
            subjectA.add(map2);
            subjectA.add(map3);
            subjectA.add(map4);
            subjectA.add(map5);
            Map<String, Object> map11 = new HashMap<>();
            Map<String, Object> map12 = new HashMap<>();
            Map<String, Object> map13 = new HashMap<>();
            Map<String, Object> map14 = new HashMap<>();
            map11.put("name","慧用工-东区");
            map11.put("value",hyg1);
            map12.put("name","慧用工-南区");
            map12.put("value",hyg2);
            map13.put("name","慧用工-西区");
            map13.put("value",hyg3);
            map14.put("name","慧用工-北区");
            map14.put("value",hyg4);
            Map<String, Object> map21 = new HashMap<>();
            Map<String, Object> map22 = new HashMap<>();
            Map<String, Object> map23 = new HashMap<>();
            Map<String, Object> map24 = new HashMap<>();
            map21.put("name","慧韩企-东区");
            map21.put("value",hhq1);
            map22.put("name","慧韩企-南区");
            map22.put("value",hhq2);
            map23.put("name","慧韩企-西区");
            map23.put("value",hhq3);
            map24.put("name","慧韩企-北区");
            map24.put("value",hhq4);
            Map<String, Object> map31 = new HashMap<>();
            Map<String, Object> map32 = new HashMap<>();
            Map<String, Object> map33 = new HashMap<>();
            Map<String, Object> map34 = new HashMap<>();
            map31.put("name","慧行销-东区");
            map31.put("value",hxx1);
            map32.put("name","慧行销-南区");
            map32.put("value",hxx2);
            map33.put("name","慧行销-西区");
            map33.put("value",hxx3);
            map34.put("name","慧行销-北区");
            map34.put("value",hxx4);
            Map<String, Object> map41 = new HashMap<>();
            Map<String, Object> map42 = new HashMap<>();
            Map<String, Object> map43 = new HashMap<>();
            Map<String, Object> map44 = new HashMap<>();
            map41.put("name","慧陈列-东区");
            map41.put("value",hcl1);
            map42.put("name","慧陈列-南区");
            map42.put("value",hcl2);
            map43.put("name","慧陈列-西区");
            map43.put("value",hcl3);
            map44.put("name","慧陈列-北区");
            map44.put("value",hcl4);
            Map<String, Object> map51 = new HashMap<>();
            Map<String, Object> map52 = new HashMap<>();
            Map<String, Object> map53 = new HashMap<>();
            Map<String, Object> map54 = new HashMap<>();
            map51.put("name","慧时尚-东区");
            map51.put("value",hss1);
            map52.put("name","慧时尚-南区");
            map52.put("value",hss2);
            map53.put("name","慧时尚-西区");
            map53.put("value",hss3);
            map54.put("name","慧时尚-北区");
            map54.put("value",hss4);

            setListValue(subjectB,map11);
            setListValue(subjectB,map12);
            setListValue(subjectB,map13);
            setListValue(subjectB,map14);
            setListValue(subjectB,map21);
            setListValue(subjectB,map22);
            setListValue(subjectB,map23);
            setListValue(subjectB,map24);
            setListValue(subjectB,map31);
            setListValue(subjectB,map32);
            setListValue(subjectB,map33);
            setListValue(subjectB,map34);
            setListValue(subjectB,map41);
            setListValue(subjectB,map42);
            setListValue(subjectB,map43);
            setListValue(subjectB,map44);
            setListValue(subjectB,map51);
            setListValue(subjectB,map52);
            setListValue(subjectB,map53);
            setListValue(subjectB,map54);
        }
        reportData.put("团队",subjectA);
        reportData.put("区域",subjectB);
        return reportData;
    }

    @ApiOperation(value = "项目执行率-总" )
    @GetMapping("/subjectExecuteRate")
    @ResponseBody
    public Map<String, Object> subjectExecuteRate(){
        List<Map<String, Object>> list = reportService.subjectExecuteRate();
        Map<String, Object> returnList = new HashMap();

        Map<String, Object> line1 = new HashMap<>();
        List<String> datax = new ArrayList<>();
        List<String> datay = new ArrayList<>();
        List<String> dataz = new ArrayList<>();
        List<Object> details = new ArrayList<>();
        for (Map<String, Object> map : list) {
            StringBuilder detail = new StringBuilder();
            detail.append(MapUtils.getString(map, "activityName")).append("<br/>");
            String name = MapUtils.getString(map, "activityName");
            if(name.length()>8){
                String substring = name.substring(0, 8);
                String substring1 = name.substring(8, name.length());
                datax.add(substring.concat("\n").concat(substring1).concat("\n").concat(MapUtils.getString(map,"count")));
            }else{
                datax.add(name.concat("\n").concat(MapUtils.getString(map,"count")));
            }
            datay.add(MapUtils.getString(map,"rate"));
            dataz.add(MapUtils.getString(map,"id"));
            detail.append("执行场次数：").append(MapUtils.getString(map,"actualRoundTotalNum")).append("<br/>");
            detail.append("计划场次数：").append(MapUtils.getString(map,"planRoundTotalNum")).append("<br/>");
            detail.append("外因影响数：").append(MapUtils.getString(map,"reasonNum")).append("<br/>");
            detail.append("执行率：").append(MapUtils.getString(map,"rate")).append("%");
            details.add(detail);
        }
        line1.put("name","执行完成率%");
        line1.put("type","line");
        line1.put("data",datay);
        returnList.put("datax",datax);
        returnList.put("datay",line1);
        returnList.put("dataz",dataz);
        returnList.put("details",details);

        Map<String, String> parentMap = portalService.getParentId("ZXXQTB");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","ZXXQTB");
        returnList.put("url",url);

        return returnList;
    }

    @ApiOperation(value = "项目执行率-项目-周期" )
    @GetMapping("/subjectExecuteCycle")
    @ResponseBody
    public Map<String, Object> subjectExecuteCycle(String id){
        Map<String, Object> returnList = new HashMap<>();
        if(StringUtil.isBlank(id)){
            return returnList;
        }
        List<Map<String, Object>> list = reportService.subjectExecuteCycle(id);

        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> bar1 = new HashMap<>();
        List<String> datax = new ArrayList<>();
        List<String> datay1 = new ArrayList<>();
        List<String> datay2 = new ArrayList<>();
        List<String> dataz = new ArrayList<>();
        List<Object> details = new ArrayList<>();
        for (Map<String, Object> map : list) {
            StringBuilder detail = new StringBuilder();
            detail.append(MapUtils.getString(map,"dateRange")).append("<br/>");
            datax.add(MapUtils.getString(map,"dateRange"));
            Integer ratex = MapUtils.getInteger(map, "ratex");
            Integer ratey = MapUtils.getInteger(map, "ratey");
            Integer reasonNum = MapUtils.getInteger(map, "reasonNum");
            datay2.add(String.valueOf(ratex));
            Integer tate = 0;
            if(ratex==0||(ratey-reasonNum)<=0){
                datay1.add(String.valueOf(0));
            }else if(ratey==0){
                datay1.add(String.valueOf(0));
            }else if(ratex >= (ratey-reasonNum)){
                tate = 100;
                datay1.add("100");
            }else{
                tate = (ratex * 100) / (ratey-reasonNum);
                datay1.add(String.valueOf(tate));
            }
            dataz.add(MapUtils.getString(map,"dateRange").concat("_").concat(MapUtils.getString(map,"id")));
            detail.append("执行场次数：").append(ratex).append("<br/>");
            detail.append("计划场次数：").append(ratey).append("<br/>");
            detail.append("外因影响数：").append(reasonNum).append("<br/>");
            detail.append("执行率：").append(tate).append("%");
            details.add(detail);
        }
        line1.put("name","执行率%");
        line1.put("type","line");
        line1.put("data",datay1);
        line1.put("yAxisIndex",1);
        bar1.put("type","bar");
        bar1.put("name","执行场次数");
        bar1.put("stack","stack");
        bar1.put("data",datay2);
        bar1.put("yAxisIndex",0);
        returnList.put("datax",datax);
        returnList.put("datay1",bar1);
        returnList.put("datay2",line1);
        returnList.put("dataz",dataz);
        returnList.put("details",details);
        return returnList;
    }

    @ApiOperation(value = "项目执行率-项目-周期-城市" )
    @GetMapping("/subjectExecuteCity")
    @ResponseBody
    public Map<String, Object> subjectExecuteCity(String id){
        Map<String, Object> returnList = new HashMap<>();
        if(StringUtil.isBlank(id)){
            return returnList;
        }
        String[] s = id.split("_");
        List<Map<String, Object>> list = reportService.subjectExecuteCity(s[1],s[0]);

        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> bar1 = new HashMap<>();
        List<String> datax = new ArrayList<>();
        List<String> datay1 = new ArrayList<>();
        List<String> datay2 = new ArrayList<>();
        List<String> details = new ArrayList<>();
        for (Map<String, Object> map : list) {
            StringBuilder str = new StringBuilder();
            String city = MapUtils.getString(map, "city");
            datax.add(city);
            Integer ratex = MapUtils.getInteger(map, "ratex");
            Integer ratey = MapUtils.getInteger(map, "ratey");
            Integer reasonNum = MapUtils.getInteger(map, "reasonNum");
            datay2.add(String.valueOf(ratex));
            Integer tate = 0;
            if(ratex==0||ratey==0||(ratey-reasonNum)<=0){
                datay1.add(String.valueOf(0));
            }else if(ratex >= (ratey-reasonNum)){
                tate = 100;
                datay1.add("100");
            }else{
                tate = (ratex * 100) / (ratey-reasonNum);
                datay1.add(String.valueOf(tate));
            }
            str.append(city).append("<br/>");
            str.append("执行场次数：").append(ratex).append("<br/>");
            str.append("计划场次数：").append(ratey).append("<br/>");
            str.append("外因影响数：").append(reasonNum).append("<br/>");
            str.append("执行率：").append(tate).append("%");
            details.add(str.toString());
        }
        line1.put("name","执行率%");
        line1.put("type","line");
        line1.put("data",datay1);
        line1.put("yAxisIndex",1);
        bar1.put("type","bar");
        bar1.put("name","执行场次数");
        bar1.put("stack","stack");
        bar1.put("data",datay2);
        bar1.put("yAxisIndex",0);
        returnList.put("datax",datax);
        returnList.put("datay1",bar1);
        returnList.put("datay2",line1);
        returnList.put("details",details);
        return returnList;
    }

    @ApiOperation(value = "招聘报表-线上总" )
    @GetMapping("/recruitmentWeekDataXs")
    @ResponseBody
    public Map<String, Object> recruitmentWeekDataXs(String startDate,String endDate) throws ParseException {
        Map<String, Object> returnList = new HashMap<>();

        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMMdd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            Calendar cale = Calendar.getInstance();
            cale.setTime(start);
            cale.add(Calendar.MONTH, 0);
            cale.set(Calendar.DAY_OF_MONTH, 1);
            start = cale.getTime();
        }
        if(StringUtil.isNotEmpty(endDate)){
            end = df.parse(endDate);
        }
        //线上所有时间段招聘数据
        List<Map<String, Object>> projects = reportService.recruitmentXsData(dfString.format(start),dfString.format(end));
        Map<String, List<Map<String, Object>>> projectsData = new HashMap<>();
        for (Map<String, Object> project : projects) {
            String jdId = MapUtils.getString(project, "jdId");
            String projectId = MapUtils.getString(project, "projectId");
            String key = jdId.concat("_").concat(projectId);
            List<Map<String, Object>> list = projectsData.get(key);
            if(CollectionUtils.isEmpty(list)) {
                List<Map<String, Object>> newList = new ArrayList<>();
                newList.add(project);
                projectsData.put(key, newList);
            }else{
                list.add(project);
            }
        }
        Integer counts = 0;
        for (List<Map<String, Object>> value : projectsData.values()) {
            if(!CollectionUtils.isEmpty(value)){
                counts += value.size();
            }
        }
        //线上所有招聘组数据
        List<String> groups = reportService.getRecruitmentGroup();
        List<List<Object>> groupCount = new ArrayList<>();
        for (int i = 0; i < groups.size(); i++) {
            List<Object> list = new ArrayList<>();
            for (int b = 0; b < counts; b++) {
                list.add(null);
            }
            groupCount.add(list);
        }

        //项目展示名称
        List<Object> names = new ArrayList<>();
        //完成率
        List<Object> roits = new ArrayList<>();
        //展示字段
        List<String> details = new ArrayList<>();
        Integer index = 0;
        for (String key : projectsData.keySet()) {
            List<Map<String, Object>> list = projectsData.get(key);
            List<Map<String, Object>> allList = new ArrayList<>();
            Integer demandFors = 0;
            Integer sumCount = 0;
            Integer sumCounts = 0;
            String name = "";
            boolean b = true;
            StringBuilder detail = new StringBuilder();
            for (Map<String, Object> map : list) {
                String id = MapUtils.getString(map, "id");
                String projectNames = MapUtils.getString(map, "projectNames");
                String jobName = MapUtils.getString(map, "jobName");
                if(StringUtil.isBlank(name)){
                    name = projectNames.concat("\n").concat(jobName);
                    names.add(name);
                }
                if(StringUtil.isBlank(detail)){
                    detail.append(projectNames).append("--").append(jobName).append("<br/>");
                }
                List<Map<String, Object>> xsData = reportService.getXsData(projectNames,jobName,dfString.format(start),dfString.format(end));
                List<Map<String, Object>> xsDataSum = reportService.getXsDataSum(projectNames,jobName);
                for (Map<String, Object> xsDatum : xsData) {
                    String groupName = MapUtils.getString(xsDatum, "groupName");
                    Integer count = MapUtils.getInteger(xsDatum, "count");
                    sumCount += count;
                    int i = groups.indexOf(groupName);
                    List<Object> g = groupCount.get(i);
                    g.set(index,count);
                }
                if(b){
                    for (Map<String, Object> xsDatum : xsDataSum) {
                        Integer count = MapUtils.getInteger(xsDatum, "count");
                        sumCounts += count;
                        b = false;
                    }
                }
                Integer demandFor = reportService.getSumDemandFor(dfString.format(start),dfString.format(end),id);
                if(demandFor!=null){
                    demandFors += demandFor;
                }
                allList.addAll(xsData);
            }
            detail.append("总需求数：").append(demandFors).append("<br/>");
            detail.append("总入职数：").append(sumCounts).append("<br/>");
            detail.append("入职数：").append(sumCount).append("<br/>");
            index++;
            if(demandFors>0 && sumCounts>0){
                Integer roit = (sumCounts * 100)/demandFors;
                roits.add(roit);
                detail.append("总完成率：").append(roit).append("%");
            }else{
                roits.add(0);
                detail.append("总完成率：").append(0).append("%");
            }
            details.add(detail.toString());
        }
        List<Map<String, Object>> bars = new ArrayList<>();
        Map<String, Object> line = new HashMap<>();
        for (List<Object> list : groupCount) {
            Map<String, Object> bar = new HashMap<>();
            bar.put("data",list);
            bar.put("type","bar");
            bar.put("stack","stack");
            bar.put("yAxisIndex",0);
            bars.add(bar);
        }
        for (int i = 0; i < groups.size(); i++) {
            Map<String, Object> map = bars.get(i);
            map.put("name",groups.get(i));
        }
        line.put("name","完成率%");
        line.put("type","line");
        line.put("data",roits);
        line.put("yAxisIndex",1);
        bars.add(line);
        returnList.put("datas",bars);
        returnList.put("names",names);
        returnList.put("details",details);
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        String startTotal = format.format(start);
        String endTotal = format.format(end);
        returnList.put("title","线上招聘报表 ".concat(startTotal).concat("-").concat(endTotal));

        Map<String, String> parentMap = portalService.getParentId("ZPXQZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","ZPXQZBGL");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "招聘报表-顾问排名" )
    @GetMapping("/employmentRanking")
    @ResponseBody
    public Map<String, Object> employmentRanking(String startDate,String endDate) throws ParseException {
        String id = "2c928fbb7129a41e01712f0c83cf2ef7";
        Map<String, Object> returnList = new HashMap<>();
        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            Calendar cale = Calendar.getInstance();
            cale.setTime(start);
            cale.add(Calendar.MONTH, 0);
            cale.set(Calendar.DAY_OF_MONTH, 1);
            start = cale.getTime();
        }
        if(StringUtil.isNotEmpty(endDate)){
            end = df.parse(endDate);
        }

        List<Map<String, Object>> list = reportService.employmentRanking(start,end);
        Map<String, Map<String, Object>> listMaps = new HashMap<>();
        for (Map<String, Object> map : list) {
            listMaps.put(MapUtils.getString(map,"operator"),map);
        }
        Map<String, Integer> maps = new HashMap<>();
        List<String> operatorNames = reportService.getEmployments(id);

        List<Object> names = new ArrayList<>();
        List<Object> gts = new ArrayList<>();
        List<Object> yys = new ArrayList<>();
        List<Object> kms = new ArrayList<>();
        List<Object> ofs = new ArrayList<>();
        List<Object> rzs = new ArrayList<>();
        List<Object> zhl = new ArrayList<>();
        for (String operatorName : operatorNames) {
            names.add(operatorName);
            Map<String, Object> map = listMaps.get(operatorName);
            if(MapUtils.isEmpty(map)){
                gts.add("");
                yys.add("");
                kms.add("");
                ofs.add("");
                rzs.add("");
                zhl.add("");
            }else{
                Integer gt = MapUtils.getInteger(map, "gt");
                Integer yy = MapUtils.getInteger(map, "yy");
                Integer km = MapUtils.getInteger(map, "km");
                Integer of = MapUtils.getInteger(map, "of");
                Integer rz = MapUtils.getInteger(map, "rz");
                if(yy == 0||rz == 0){
                    zhl.add(0);
                }else{
                    Integer rax = (rz*100) / yy;
                    zhl.add(rax);
                }
                gts.add(gt==0?"":gt);
                yys.add(yy==0?"":yy);
                kms.add(km==0?"":km);
                ofs.add(of==0?"":of);
                rzs.add(rz==0?"":rz);
            }

        }
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        Map<String, Object> bar3 = new HashMap<>();
        Map<String, Object> bar4 = new HashMap<>();
        Map<String, Object> bar5 = new HashMap<>();
        Map<String, Object> line1 = new HashMap<>();

        bar1.put("data",gts);
        bar1.put("name","沟通");
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("yAxisIndex",0);
        bar2.put("data",yys);
        bar2.put("name","邀约");
        bar2.put("type","bar");
        bar2.put("stack","stack");
        bar2.put("yAxisIndex",0);
        bar3.put("data",kms);
        bar3.put("name","到面");
        bar3.put("type","bar");
        bar3.put("stack","stack");
        bar3.put("yAxisIndex",0);
        bar4.put("data",ofs);
        bar4.put("name","offer");
        bar4.put("type","bar");
        bar4.put("stack","stack");
        bar4.put("yAxisIndex",0);
        bar5.put("data",rzs);
        bar5.put("name","入职");
        bar5.put("type","bar");
        bar5.put("stack","stack");
        bar5.put("yAxisIndex",0);

        line1.put("data",zhl);
        line1.put("name","转化率%");
        line1.put("type","line");
        line1.put("yAxisIndex",1);

        List<Object> datas = new ArrayList<>();
        datas.add(bar1);
        datas.add(bar2);
        datas.add(bar3);
        datas.add(bar4);
        datas.add(bar5);
        datas.add(line1);
        returnList.put("datas",datas);
        returnList.put("names",names);
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        String startTotal = format.format(start);
        String endTotal = format.format(end);
        returnList.put("title","顾问完成情况 ".concat(startTotal).concat("-").concat(endTotal));

        Map<String, String> parentMap = portalService.getParentId("recruitmentData");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","recruitmentData");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "招聘报表-线下-按工时" )
    @GetMapping("/recruitmentWeekDataXxByTime")
    @ResponseBody
    public Map<String, Object> recruitmentWeekDataXxByTime(String startDate,String endDate) throws ParseException {
        Map<String, Object> returnList = new HashMap<>();
        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMMdd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(start);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(start);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(start);
                long diff = calendar.getTime().getTime() - start.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(start);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    start = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(start);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    start = cale.getTime();
                }
            }
        }
        if(StringUtil.isNotEmpty(endDate)) {
            end = df.parse(endDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(end);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(end);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(end);
                long diff = calendar.getTime().getTime() - end.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(end);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    end = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(end);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    end = cale.getTime();
                }
            }
        }
        start = getFirstDate(start);
        end = getLastDate(end);
        List<Map<String, Object>> list = reportService.recruitmentWeekDataXxByAscertain(dfString.format(start),dfString.format(end),"按工时");
        List<Map<String, Object>> listSum = reportService.recruitmentWeekDataXxByAscertainSum("按工时");
        Map<String, List<Map<String, Object>>> zpList = new HashMap<>();
        Map<String, List<Map<String, Object>>> zpListSum = new HashMap<>();
        for (Map<String, Object> map : list) {
            String jdId = MapUtils.getString(map,"jdId");
            String subjectId = MapUtils.getString(map,"subjectId");
            String key = jdId.concat("_").concat(subjectId);
            List<Map<String, Object>> zplist = zpList.get(key);
            if(CollectionUtils.isEmpty(zplist)){
                List<Map<String, Object>> s = new ArrayList<>();
                s.add(map);
                zpList.put(key,s);
            }else{
                zplist.add(map);
                zpList.put(key,zplist);
            }
        }
        for (Map<String, Object> map : listSum) {
            String jdId = MapUtils.getString(map,"jdId");
            String subjectId = MapUtils.getString(map,"subjectId");
            String key = jdId.concat("_").concat(subjectId);
            List<Map<String, Object>> zplist = zpListSum.get(key);
            if(CollectionUtils.isEmpty(zplist)){
                List<Map<String, Object>> s = new ArrayList<>();
                s.add(map);
                zpListSum.put(key,s);
            }else{
                zplist.add(map);
                zpListSum.put(key,zplist);
            }
        }
        //计算
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        List<String> list3 = new ArrayList<>();
        List<String> list4 = new ArrayList<>();
        List<String> list5 = new ArrayList<>();
        List<String> names = new ArrayList<>();
        List<String> details = new ArrayList<>();
        for (String keys : zpList.keySet()) {
            List<Map<String, Object>> zplist = zpList.get(keys);
            List<Map<String, Object>> zplistSum = zpListSum.get(keys);
            StringBuilder detail = new StringBuilder();
            if(!CollectionUtils.isEmpty(zplist)){
                Integer sumFinished = 0;
                Integer sumFinisheds = 0;
                Integer sumDemandFor = 0;
                String name = "";
                for (Map<String, Object> map : zplist) {
                    String jdId = MapUtils.getString(map,"jdId");
                    String subjectId = MapUtils.getString(map,"subjectId");
                    String jobName = MapUtils.getString(map,"jobName");
                    String projectNames = MapUtils.getString(map,"projectNames");
                    String key = jdId.concat("_").concat(subjectId);
                    if(StringUtil.isBlank(name)){
                        name = projectNames.concat("\n").concat(jobName);
                        names.add(name);
                        Integer sumDemandForById = reportService.getSumDemandForByAscertain(key.split("_")[0],key.split("_")[1],"按工时");
                        sumDemandFor += sumDemandForById;
                        break;
                    }
                }
                String v1 = "";
                String v2 = "";
                String v3 = "";
                String v4 = "";
                for (Map<String, Object> map : zplist) {
                    //区域
                    String rcsArea = MapUtils.getString(map, "rcsArea");
                    //完成数
                    Integer finishedNum = MapUtils.getInteger(map, "finishedNum");
                    sumFinished += finishedNum;
                    if("东区".equals(rcsArea)){
                        v1 = String.valueOf(finishedNum);
                    }else if("南区".equals(rcsArea)){
                        v2 = String.valueOf(finishedNum);
                    }else if("西区".equals(rcsArea)){
                        v3 = String.valueOf(finishedNum);
                    }else if("北区".equals(rcsArea)){
                        v4 = String.valueOf(finishedNum);
                    }
                }
                for (Map<String, Object> map : zplistSum) {
                    //完成数
                    Integer finishedNum = MapUtils.getInteger(map, "finishedNum");
                    sumFinisheds += finishedNum;
                }
                list1.add(v1);
                list2.add(v2);
                list3.add(v3);
                list4.add(v4);
                detail.append("总需求数：").append(sumDemandFor).append("<br/>");
                detail.append("总完成数：").append(sumFinisheds).append("<br/>");
                if(StringUtil.isNotBlank(v1)){
                    detail.append("东区完成数：").append(v1).append("<br/>");
                }
                if(StringUtil.isNotBlank(v2)){
                    detail.append("南区完成数：").append(v2).append("<br/>");
                }
                if(StringUtil.isNotBlank(v3)){
                    detail.append("西区完成数：").append(v3).append("<br/>");
                }
                if(StringUtil.isNotBlank(v4)){
                    detail.append("北区完成数：").append(v4).append("<br/>");
                }

                if(sumDemandFor==0||sumFinisheds==0){
                    list5.add("0");
                    detail.append("总完成率：").append(0).append("%");
                }else{
                    Integer value = (sumFinisheds * 100)/sumDemandFor;
                    list5.add(String.valueOf(value));
                    detail.append("总完成率：").append(value).append("%");
                }
                details.add(detail.toString());
            }
        }
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        Map<String, Object> bar3 = new HashMap<>();
        Map<String, Object> bar4 = new HashMap<>();
        Map<String, Object> line1 = new HashMap<>();

        bar1.put("data",list1);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("yAxisIndex",0);
        bar1.put("name","东区");
        bar2.put("data",list2);
        bar2.put("type","bar");
        bar2.put("stack","stack");
        bar2.put("yAxisIndex",0);
        bar2.put("name","南区");
        bar3.put("data",list3);
        bar3.put("type","bar");
        bar3.put("stack","stack");
        bar3.put("yAxisIndex",0);
        bar3.put("name","西区");
        bar4.put("data",list4);
        bar4.put("type","bar");
        bar4.put("stack","stack");
        bar4.put("yAxisIndex",0);
        bar4.put("name","北区");
        line1.put("name","完成率%");
        line1.put("type","line");
        line1.put("data",list5);
        line1.put("yAxisIndex",1);
        List<Object> datas = new ArrayList<>();

        datas.add(bar1);
        datas.add(bar2);
        datas.add(bar3);
        datas.add(bar4);
        datas.add(line1);
        returnList.put("datas",datas);
        returnList.put("names",names);
        returnList.put("details",details);
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        String startTotal = format.format(start);
        String endTotal = format.format(end);
        returnList.put("title","线下招聘报表 ".concat(startTotal).concat("-").concat(endTotal));

        Map<String, String> parentMap = portalService.getParentId("XXZPXQZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XXZPXQZBGL");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "区域完成率-线下-按工时" )
    @GetMapping("/areaFinishedRatioByTime")
    @ResponseBody
    public Map<String, Object> areaFinishedRatioByTime(String startDate,String endDate) throws ParseException {
        Map<String, Object> returnList = new HashMap<>();
        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMMdd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(start);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(start);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(start);
                long diff = calendar.getTime().getTime() - start.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(start);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    start = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(start);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    start = cale.getTime();
                }
            }
        }
        if(StringUtil.isNotEmpty(endDate)) {
            end = df.parse(endDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(end);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(end);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(end);
                long diff = calendar.getTime().getTime() - end.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(end);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    end = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(end);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    end = cale.getTime();
                }
            }
        }
        start = getFirstDate(start);
        end = getLastDate(end);
        List<Map<String, Object>> listFinished = reportService.areaFinishedByAscertain(dfString.format(start),dfString.format(end),"按工时");
        List<Map<String, Object>> listFinishedSum = reportService.areaFinishedByAscertainSum("按工时");
        List<Map<String, Object>> listDemandFor = reportService.areaDemandForByAscertain(dfString.format(start),dfString.format(end),"按工时");
        Integer dq = 0;
        Integer nq = 0;
        Integer xq = 0;
        Integer bq = 0;
        Integer dq1 = 0;
        Integer nq1 = 0;
        Integer xq1 = 0;
        Integer bq1 = 0;
        Integer dq2 = 0;
        Integer nq2 = 0;
        Integer xq2 = 0;
        Integer bq2 = 0;
        Integer dq3 = 0;
        Integer nq3 = 0;
        Integer xq3 = 0;
        Integer bq3 = 0;
        Map<String, Integer> finishedMap = new HashMap<>();
        Map<String, Integer> finishedMapSum = new HashMap<>();
        for (Map<String, Object> map : listFinished) {
            finishedMap.put(MapUtils.getString(map, "rcsArea"),MapUtils.getInteger(map, "finishedNum"));
        }
        for (Map<String, Object> map : listFinishedSum) {
            finishedMapSum.put(MapUtils.getString(map, "rcsArea"),MapUtils.getInteger(map, "finishedNum"));
        }
        for (Map<String, Object> map : listDemandFor) {
            String rcsArea = MapUtils.getString(map, "rcsArea");
            Integer demandFor = MapUtils.getInteger(map, "demandFor");
            Integer finished = finishedMap.get(rcsArea);
            Integer finishedSum = finishedMapSum.get(rcsArea);
            Integer ratio = 0;
            if(demandFor==null){
                demandFor = 0;
            }
            if(finished==null){
                finished = 0;
            }
            if(finishedSum==null){
                finishedSum = 0;
            }
            if(demandFor>0 && finishedSum>0){
                ratio = (finishedSum * 100) / demandFor;
            }
            if("东区".equals(rcsArea)){
                dq = ratio;
                dq1 = demandFor;
                dq2 = finished;
                dq3 = finishedSum;
            }else if("南区".equals(rcsArea)){
                nq = ratio;
                nq1 = demandFor;
                nq2 = finished;
                nq3 = finishedSum;
            }else if("西区".equals(rcsArea)){
                xq = ratio;
                xq1 = demandFor;
                xq2 = finished;
                xq3 = finishedSum;
            }else if("北区".equals(rcsArea)){
                bq = ratio;
                bq1 = demandFor;
                bq2 = finished;
                bq3 = finishedSum;
            }
        }
        List<String> names = new ArrayList<>();
        names.add("东区");
        names.add("南区");
        names.add("西区");
        names.add("北区");
        List<Integer> counts = new ArrayList<>();
        List<Integer> finisheds = new ArrayList<>();
        List<Object> details = new ArrayList<>();
        counts.add(dq);
        counts.add(nq);
        counts.add(xq);
        counts.add(bq);
        finisheds.add(dq2);
        finisheds.add(nq2);
        finisheds.add(xq2);
        finisheds.add(bq2);
        StringBuilder detail1 = new StringBuilder();
        StringBuilder detail2 = new StringBuilder();
        StringBuilder detail3 = new StringBuilder();
        StringBuilder detail4 = new StringBuilder();
        detail1.append("东区").append("<br/>");
        detail1.append("总需求数：").append(dq1).append("<br/>");
        detail1.append("总完成数：").append(dq3).append("<br/>");
        detail1.append("完成数：").append(dq2).append("<br/>");
        detail1.append("总完成率：").append(dq).append("%").append("<br/>");
        detail2.append("南区").append("<br/>");
        detail2.append("总需求数：").append(nq1).append("<br/>");
        detail2.append("总完成数：").append(nq3).append("<br/>");
        detail2.append("完成数：").append(nq2).append("<br/>");
        detail2.append("总完成率：").append(nq).append("%").append("<br/>");
        detail3.append("西区").append("<br/>");
        detail3.append("总需求数：").append(xq1).append("<br/>");
        detail3.append("总完成数：").append(xq3).append("<br/>");
        detail3.append("完成数：").append(xq2).append("<br/>");
        detail3.append("总完成率：").append(xq).append("%").append("<br/>");
        detail4.append("北区").append("<br/>");
        detail4.append("总需求数：").append(bq1).append("<br/>");
        detail4.append("总完成数：").append(bq3).append("<br/>");
        detail4.append("完成数：").append(bq2).append("<br/>");
        detail4.append("总完成率：").append(bq).append("%").append("<br/>");
        details.add(detail1);
        details.add(detail2);
        details.add(detail3);
        details.add(detail4);
        List<Object> datas = new ArrayList<>();

        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> bar1 = new HashMap<>();
        line1.put("name","完成率%");
        line1.put("type","line");
        line1.put("data",counts);
        line1.put("yAxisIndex",1);

        bar1.put("data",finisheds);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("yAxisIndex",0);
        bar1.put("name","完成数");
        datas.add(bar1);
        datas.add(line1);
        returnList.put("datas",datas);
        returnList.put("names",names);
        returnList.put("details",details);

        Map<String, String> parentMap = portalService.getParentId("XXZPXQZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XXZPXQZBGL");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "招聘报表-线下-按确定人数" )
    @GetMapping("/recruitmentWeekDataXxByIndeterminacy")
    @ResponseBody
    public Map<String, Object> recruitmentWeekDataXxByIndeterminacy(String startDate,String endDate) throws ParseException {
        Map<String, Object> returnList = new HashMap<>();
        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMMdd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(start);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(start);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(start);
                long diff = calendar.getTime().getTime() - start.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(start);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    start = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(start);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    start = cale.getTime();
                }
            }
        }
        if(StringUtil.isNotEmpty(endDate)) {
            end = df.parse(endDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(end);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(end);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(end);
                long diff = calendar.getTime().getTime() - end.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(end);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    end = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(end);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    end = cale.getTime();
                }
            }
        }
        start = getFirstDate(start);
        end = getLastDate(end);
        List<Map<String, Object>> list = reportService.recruitmentWeekDataXxByAscertain(dfString.format(start),dfString.format(end),"按确定人数");
        List<Map<String, Object>> listSum = reportService.recruitmentWeekDataXxByAscertainSum("按确定人数");
        Map<String, List<Map<String, Object>>> zpList = new HashMap<>();
        Map<String, List<Map<String, Object>>> zpListSum = new HashMap<>();
        for (Map<String, Object> map : list) {
            String jdId = MapUtils.getString(map,"jdId");
            String subjectId = MapUtils.getString(map,"subjectId");
            String key = jdId.concat("_").concat(subjectId);
            List<Map<String, Object>> zplist = zpList.get(key);
            if(CollectionUtils.isEmpty(zplist)){
                List<Map<String, Object>> s = new ArrayList<>();
                s.add(map);
                zpList.put(key,s);
            }else{
                zplist.add(map);
                zpList.put(key,zplist);
            }
        }
        for (Map<String, Object> map : listSum) {
            String jdId = MapUtils.getString(map,"jdId");
            String subjectId = MapUtils.getString(map,"subjectId");
            String key = jdId.concat("_").concat(subjectId);
            List<Map<String, Object>> zplist = zpListSum.get(key);
            if(CollectionUtils.isEmpty(zplist)){
                List<Map<String, Object>> s = new ArrayList<>();
                s.add(map);
                zpListSum.put(key,s);
            }else{
                zplist.add(map);
                zpListSum.put(key,zplist);
            }
        }
        //计算
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        List<String> list3 = new ArrayList<>();
        List<String> list4 = new ArrayList<>();
        List<String> list5 = new ArrayList<>();
        List<String> names = new ArrayList<>();
        List<String> details = new ArrayList<>();
        for (String keys : zpList.keySet()) {
            List<Map<String, Object>> zplist = zpList.get(keys);
            List<Map<String, Object>> zplistSum = zpListSum.get(keys);
            StringBuilder detail = new StringBuilder();
            if(!CollectionUtils.isEmpty(zplist)){
                Integer sumFinished = 0;
                Integer sumFinisheds = 0;
                Integer sumDemandFor = 0;
                String name = "";
                for (Map<String, Object> map : zplist) {
                    String jdId = MapUtils.getString(map,"jdId");
                    String subjectId = MapUtils.getString(map,"subjectId");
                    String jobName = MapUtils.getString(map,"jobName");
                    String projectNames = MapUtils.getString(map,"projectNames");
                    String key = jdId.concat("_").concat(subjectId);
                    if(StringUtil.isBlank(name)){
                        name = projectNames.concat("\n").concat(jobName);
                        names.add(name);
                        Integer sumDemandForById = reportService.getSumDemandForByAscertain(key.split("_")[0],key.split("_")[1],"按确定人数");
                        sumDemandFor += sumDemandForById;
                        break;
                    }
                }
                String v1 = "";
                String v2 = "";
                String v3 = "";
                String v4 = "";
                for (Map<String, Object> map : zplist) {
                    //区域
                    String rcsArea = MapUtils.getString(map, "rcsArea");
                    //完成数
                    Integer finishedNum = MapUtils.getInteger(map, "finishedNum");
                    sumFinished += finishedNum;
                    if("东区".equals(rcsArea)){
                        v1 = String.valueOf(finishedNum);
                    }else if("南区".equals(rcsArea)){
                        v2 = String.valueOf(finishedNum);
                    }else if("西区".equals(rcsArea)){
                        v3 = String.valueOf(finishedNum);
                    }else if("北区".equals(rcsArea)){
                        v4 = String.valueOf(finishedNum);
                    }
                }
                for (Map<String, Object> map : zplistSum) {
                    //完成数
                    Integer finishedNum = MapUtils.getInteger(map, "finishedNum");
                    sumFinisheds += finishedNum;
                }
                list1.add(v1);
                list2.add(v2);
                list3.add(v3);
                list4.add(v4);
                detail.append("总需求数：").append(sumDemandFor).append("<br/>");
                detail.append("总完成数：").append(sumFinisheds).append("<br/>");
                if(StringUtil.isNotBlank(v1)){
                    detail.append("东区完成数：").append(v1).append("<br/>");
                }
                if(StringUtil.isNotBlank(v2)){
                    detail.append("南区完成数：").append(v2).append("<br/>");
                }
                if(StringUtil.isNotBlank(v3)){
                    detail.append("西区完成数：").append(v3).append("<br/>");
                }
                if(StringUtil.isNotBlank(v4)){
                    detail.append("北区完成数：").append(v4).append("<br/>");
                }

                if(sumDemandFor==0||sumFinisheds==0){
                    list5.add("0");
                    detail.append("总完成率：").append(0).append("%");
                }else{
                    Integer value = (sumFinisheds * 100)/sumDemandFor;
                    list5.add(String.valueOf(value));
                    detail.append("总完成率：").append(value).append("%");
                }
                details.add(detail.toString());
            }
        }
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        Map<String, Object> bar3 = new HashMap<>();
        Map<String, Object> bar4 = new HashMap<>();
        Map<String, Object> line1 = new HashMap<>();

        bar1.put("data",list1);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("yAxisIndex",0);
        bar1.put("name","东区");
        bar2.put("data",list2);
        bar2.put("type","bar");
        bar2.put("stack","stack");
        bar2.put("yAxisIndex",0);
        bar2.put("name","南区");
        bar3.put("data",list3);
        bar3.put("type","bar");
        bar3.put("stack","stack");
        bar3.put("yAxisIndex",0);
        bar3.put("name","西区");
        bar4.put("data",list4);
        bar4.put("type","bar");
        bar4.put("stack","stack");
        bar4.put("yAxisIndex",0);
        bar4.put("name","北区");
        line1.put("name","完成率%");
        line1.put("type","line");
        line1.put("data",list5);
        line1.put("yAxisIndex",1);
        List<Object> datas = new ArrayList<>();

        datas.add(bar1);
        datas.add(bar2);
        datas.add(bar3);
        datas.add(bar4);
        datas.add(line1);
        returnList.put("datas",datas);
        returnList.put("names",names);
        returnList.put("details",details);
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        String startTotal = format.format(start);
        String endTotal = format.format(end);
        returnList.put("title","线下招聘报表 ".concat(startTotal).concat("-").concat(endTotal));

        Map<String, String> parentMap = portalService.getParentId("XXZPXQZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XXZPXQZBGL");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "区域完成率-线下-按确定人数" )
    @GetMapping("/areaFinishedRatioByIndeterminacy")
    @ResponseBody
    public Map<String, Object> areaFinishedRatioByIndeterminacy(String startDate,String endDate) throws ParseException {
        Map<String, Object> returnList = new HashMap<>();
        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMMdd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(start);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(start);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(start);
                long diff = calendar.getTime().getTime() - start.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(start);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    start = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(start);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    start = cale.getTime();
                }
            }
        }
        if(StringUtil.isNotEmpty(endDate)) {
            end = df.parse(endDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(end);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(end);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(end);
                long diff = calendar.getTime().getTime() - end.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(end);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    end = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(end);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    end = cale.getTime();
                }
            }
        }
        start = getFirstDate(start);
        end = getLastDate(end);
        List<Map<String, Object>> listFinished = reportService.areaFinishedByAscertain(dfString.format(start),dfString.format(end),"按确定人数");
        List<Map<String, Object>> listFinishedSum = reportService.areaFinishedByAscertainSum("按确定人数");
        List<Map<String, Object>> listDemandFor = reportService.areaDemandForByAscertain(dfString.format(start),dfString.format(end),"按确定人数");
        Integer dq = 0;
        Integer nq = 0;
        Integer xq = 0;
        Integer bq = 0;
        Integer dq1 = 0;
        Integer nq1 = 0;
        Integer xq1 = 0;
        Integer bq1 = 0;
        Integer dq2 = 0;
        Integer nq2 = 0;
        Integer xq2 = 0;
        Integer bq2 = 0;
        Integer dq3 = 0;
        Integer nq3 = 0;
        Integer xq3 = 0;
        Integer bq3 = 0;
        Map<String, Integer> finishedMap = new HashMap<>();
        Map<String, Integer> finishedMapSum = new HashMap<>();
        for (Map<String, Object> map : listFinished) {
            finishedMap.put(MapUtils.getString(map, "rcsArea"),MapUtils.getInteger(map, "finishedNum"));
        }
        for (Map<String, Object> map : listFinishedSum) {
            finishedMapSum.put(MapUtils.getString(map, "rcsArea"),MapUtils.getInteger(map, "finishedNum"));
        }
        for (Map<String, Object> map : listDemandFor) {
            String rcsArea = MapUtils.getString(map, "rcsArea");
            Integer demandFor = MapUtils.getInteger(map, "demandFor");
            Integer finished = finishedMap.get(rcsArea);
            Integer finishedSum = finishedMapSum.get(rcsArea);
            Integer ratio = 0;
            if(demandFor==null){
                demandFor = 0;
            }
            if(finished==null){
                finished = 0;
            }
            if(finishedSum==null){
                 finishedSum = 0;
            }
            if(demandFor>0 && finishedSum>0){
                ratio = (finishedSum * 100) / demandFor;
            }
            if("东区".equals(rcsArea)){
                dq = ratio;
                dq1 = demandFor;
                dq2 = finished;
                dq3 = finishedSum;
            }else if("南区".equals(rcsArea)){
                nq = ratio;
                nq1 = demandFor;
                nq2 = finished;
                nq3 = finishedSum;
            }else if("西区".equals(rcsArea)){
                xq = ratio;
                xq1 = demandFor;
                xq2 = finished;
                xq3 = finishedSum;
            }else if("北区".equals(rcsArea)){
                bq = ratio;
                bq1 = demandFor;
                bq2 = finished;
                bq3 = finishedSum;
            }
        }
        List<String> names = new ArrayList<>();
        names.add("东区");
        names.add("南区");
        names.add("西区");
        names.add("北区");
        List<Integer> counts = new ArrayList<>();
        List<Integer> finisheds = new ArrayList<>();
        List<Object> details = new ArrayList<>();
        counts.add(dq);
        counts.add(nq);
        counts.add(xq);
        counts.add(bq);
        finisheds.add(dq2);
        finisheds.add(nq2);
        finisheds.add(xq2);
        finisheds.add(bq2);
        StringBuilder detail1 = new StringBuilder();
        StringBuilder detail2 = new StringBuilder();
        StringBuilder detail3 = new StringBuilder();
        StringBuilder detail4 = new StringBuilder();
        detail1.append("东区").append("<br/>");
        detail1.append("总需求数：").append(dq1).append("<br/>");
        detail1.append("总完成数：").append(dq3).append("<br/>");
        detail1.append("完成数：").append(dq2).append("<br/>");
        detail1.append("总完成率：").append(dq).append("%").append("<br/>");
        detail2.append("南区").append("<br/>");
        detail2.append("总需求数：").append(nq1).append("<br/>");
        detail2.append("总完成数：").append(nq3).append("<br/>");
        detail2.append("完成数：").append(nq2).append("<br/>");
        detail2.append("总完成率：").append(nq).append("%").append("<br/>");
        detail3.append("西区").append("<br/>");
        detail3.append("总需求数：").append(xq1).append("<br/>");
        detail3.append("总完成数：").append(xq3).append("<br/>");
        detail3.append("完成数：").append(xq2).append("<br/>");
        detail3.append("总完成率：").append(xq).append("%").append("<br/>");
        detail4.append("北区").append("<br/>");
        detail4.append("总需求数：").append(bq1).append("<br/>");
        detail4.append("总完成数：").append(bq3).append("<br/>");
        detail4.append("完成数：").append(bq2).append("<br/>");
        detail4.append("总完成率：").append(bq).append("%").append("<br/>");
        details.add(detail1);
        details.add(detail2);
        details.add(detail3);
        details.add(detail4);
        List<Object> datas = new ArrayList<>();

        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> bar1 = new HashMap<>();
        line1.put("name","完成率%");
        line1.put("type","line");
        line1.put("data",counts);
        line1.put("yAxisIndex",1);

        bar1.put("data",finisheds);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("yAxisIndex",0);
        bar1.put("name","完成数");
        datas.add(bar1);
        datas.add(line1);
        returnList.put("datas",datas);
        returnList.put("names",names);
        returnList.put("details",details);

        Map<String, String> parentMap = portalService.getParentId("XXZPXQZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XXZPXQZBGL");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "招聘报表-线下-不确定人数" )
    @GetMapping("/recruitmentWeekDataXxByPeople")
    @ResponseBody
    public Map<String, Object> recruitmentWeekDataXxByPeople(String startDate,String endDate) throws ParseException {
        Map<String, Object> returnList = new HashMap<>();
        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMMdd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(start);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(start);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(start);
                long diff = calendar.getTime().getTime() - start.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(start);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    start = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(start);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    start = cale.getTime();
                }
            }
        }
        if(StringUtil.isNotEmpty(endDate)) {
            end = df.parse(endDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(end);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(end);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(end);
                long diff = calendar.getTime().getTime() - end.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(end);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    end = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(end);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    end = cale.getTime();
                }
            }
        }
        start = getFirstDate(start);
        end = getLastDate(end);
        List<Map<String, Object>> list = reportService.recruitmentWeekDataXxByIndeterminacy(dfString.format(start),dfString.format(end),"不确定人数");
        Map<String, List<Map<String, Object>>> zpList = new HashMap<>();
        for (Map<String, Object> map : list) {
            String jdId = MapUtils.getString(map,"jdId");
            String subjectId = MapUtils.getString(map,"subjectId");
            String key = jdId.concat("_").concat(subjectId);
            List<Map<String, Object>> zplist = zpList.get(key);
            if(CollectionUtils.isEmpty(zplist)){
                List<Map<String, Object>> s = new ArrayList<>();
                s.add(map);
                zpList.put(key,s);
            }else{
                zplist.add(map);
                zpList.put(key,zplist);
            }
        }
        //计算
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        List<String> list3 = new ArrayList<>();
        List<String> list4 = new ArrayList<>();
        List<String> list5 = new ArrayList<>();
        List<String> names = new ArrayList<>();
        List<String> details = new ArrayList<>();
        for (String keys : zpList.keySet()) {
            List<Map<String, Object>> zplist = zpList.get(keys);
            StringBuilder detail = new StringBuilder();
            if(!CollectionUtils.isEmpty(zplist)){
                Integer sumFinished = 0;
                Integer sumDemandFor = 0;
                String name = "";
                for (Map<String, Object> map : zplist) {
                    Integer plannedNum = MapUtils.getInteger(map,"plannedNum");
                    String jobName = MapUtils.getString(map,"jobName");
                    String projectNames = MapUtils.getString(map,"projectNames");
                    if(StringUtil.isBlank(name)){
                        name = projectNames.concat("\n").concat(jobName);
                        names.add(name);
                    }
                    sumDemandFor += plannedNum;
                }
                String v1 = "";
                String v2 = "";
                String v3 = "";
                String v4 = "";
                for (Map<String, Object> map : zplist) {
                    //区域
                    String rcsArea = MapUtils.getString(map, "rcsArea");
                    //完成数
                    Integer finishedNum = MapUtils.getInteger(map, "finishedNum");
                    sumFinished += finishedNum;
                    if("东区".equals(rcsArea)){
                        v1 = String.valueOf(finishedNum);
                    }else if("南区".equals(rcsArea)){
                        v2 = String.valueOf(finishedNum);
                    }else if("西区".equals(rcsArea)){
                        v3 = String.valueOf(finishedNum);
                    }else if("北区".equals(rcsArea)){
                        v4 = String.valueOf(finishedNum);
                    }
                }
                list1.add(v1);
                list2.add(v2);
                list3.add(v3);
                list4.add(v4);
                detail.append("计划总数：").append(sumDemandFor).append("<br/>");
                if(StringUtil.isNotBlank(v1)){
                    detail.append("东区：").append(v1).append("<br/>");
                }
                if(StringUtil.isNotBlank(v2)){
                    detail.append("南区：").append(v2).append("<br/>");
                }
                if(StringUtil.isNotBlank(v3)){
                    detail.append("西区：").append(v3).append("<br/>");
                }
                if(StringUtil.isNotBlank(v4)){
                    detail.append("北区：").append(v4).append("<br/>");
                }

                if(sumDemandFor==0||sumFinished==0){
                    list5.add("0");
                    detail.append("推荐率：").append(0).append("%");
                }else{
                    Integer value = (sumFinished * 100)/sumDemandFor;
                    list5.add(String.valueOf(value));
                    detail.append("推荐率：").append(value).append("%");
                }
                details.add(detail.toString());
            }
        }
        Map<String, Object> bar1 = new HashMap<>();
        Map<String, Object> bar2 = new HashMap<>();
        Map<String, Object> bar3 = new HashMap<>();
        Map<String, Object> bar4 = new HashMap<>();
        Map<String, Object> line1 = new HashMap<>();

        bar1.put("data",list1);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("yAxisIndex",0);
        bar1.put("name","东区");
        bar2.put("data",list2);
        bar2.put("type","bar");
        bar2.put("stack","stack");
        bar2.put("yAxisIndex",0);
        bar2.put("name","南区");
        bar3.put("data",list3);
        bar3.put("type","bar");
        bar3.put("stack","stack");
        bar3.put("yAxisIndex",0);
        bar3.put("name","西区");
        bar4.put("data",list4);
        bar4.put("type","bar");
        bar4.put("stack","stack");
        bar4.put("yAxisIndex",0);
        bar4.put("name","北区");
        line1.put("name","推荐率%");
        line1.put("type","line");
        line1.put("data",list5);
        line1.put("yAxisIndex",1);
        List<Object> datas = new ArrayList<>();

        datas.add(bar1);
        datas.add(bar2);
        datas.add(bar3);
        datas.add(bar4);
        datas.add(line1);
        returnList.put("datas",datas);
        returnList.put("names",names);
        returnList.put("details",details);
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        String startTotal = format.format(start);
        String endTotal = format.format(end);
        returnList.put("title","线下招聘报表 ".concat(startTotal).concat("-").concat(endTotal));

        Map<String, String> parentMap = portalService.getParentId("XXZPXQZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XXZPXQZBGL");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "区域完成率-线下-不确定人数" )
    @GetMapping("/areaFinishedRatioByPeople")
    @ResponseBody
    public Map<String, Object> areaFinishedRatioByPeople(String startDate,String endDate) throws ParseException {
        Map<String, Object> returnList = new HashMap<>();
        Date start = new Date();
        Date end = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dfString = new SimpleDateFormat("yyyyMMdd");
        if(StringUtil.isNotEmpty(startDate)){
            start = df.parse(startDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(start);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(start);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(start);
                long diff = calendar.getTime().getTime() - start.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(start);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    start = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(start);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    start = cale.getTime();
                }
            }
        }
        if(StringUtil.isNotEmpty(endDate)) {
            end = df.parse(endDate);
        }else{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(end);
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            String nowDay = sdf.format(end);
            String firstDay = sdf.format(calendar.getTime());
            if(!nowDay.equals(firstDay)){
                Integer week = getIntegerWeek(end);
                long diff = calendar.getTime().getTime() - end.getTime();
                long days = diff / (1000 * 60 * 60 * 24);
                if(Math.abs(days)>=13){
                    calendar.setTime(end);
                    calendar.add(Calendar.DAY_OF_YEAR, -13);
                    end = calendar.getTime();
                }else{
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(end);
                    cale.add(Calendar.DAY_OF_YEAR, (int) -(Math.abs(days)));
                    end = cale.getTime();
                }
            }
        }
        start = getFirstDate(start);
        end = getLastDate(end);
        List<Map<String, Object>> listFinished = reportService.areaFinishedByIndeterminacy(dfString.format(start),dfString.format(end),"不确定人数");
        Integer dq = 0;
        Integer nq = 0;
        Integer xq = 0;
        Integer bq = 0;
        Integer dq1 = 0;
        Integer nq1 = 0;
        Integer xq1 = 0;
        Integer bq1 = 0;
        Integer dq2 = 0;
        Integer nq2 = 0;
        Integer xq2 = 0;
        Integer bq2 = 0;
        for (Map<String, Object> map : listFinished) {
            String rcsArea = MapUtils.getString(map, "rcsArea");
            Integer demandFor = MapUtils.getInteger(map, "plannedNum");
            Integer finished = MapUtils.getInteger(map, "finishedNum");
            Integer ratio = 0;
            if(demandFor==null){
                demandFor = 0;
            }
            if(finished==null){
                finished = 0;
            }
            if(demandFor>0 && finished>0){
                ratio = (finished * 100) / demandFor;
            }
            if("东区".equals(rcsArea)){
                dq = ratio;
                dq1 = demandFor;
                dq2 = finished;
            }else if("南区".equals(rcsArea)){
                nq = ratio;
                nq1 = demandFor;
                nq2 = finished;
            }else if("西区".equals(rcsArea)){
                xq = ratio;
                xq1 = demandFor;
                xq2 = finished;
            }else if("北区".equals(rcsArea)){
                bq = ratio;
                bq1 = demandFor;
                bq2 = finished;
            }
        }
        List<String> names = new ArrayList<>();
        names.add("东区");
        names.add("南区");
        names.add("西区");
        names.add("北区");
        List<Integer> counts = new ArrayList<>();
        List<Integer> finisheds = new ArrayList<>();
        List<Object> details = new ArrayList<>();
        counts.add(dq);
        counts.add(nq);
        counts.add(xq);
        counts.add(bq);
        finisheds.add(dq2);
        finisheds.add(nq2);
        finisheds.add(xq2);
        finisheds.add(bq2);
        StringBuilder detail1 = new StringBuilder();
        StringBuilder detail2 = new StringBuilder();
        StringBuilder detail3 = new StringBuilder();
        StringBuilder detail4 = new StringBuilder();
        detail1.append("东区").append("<br/>");
        detail1.append("计划数：").append(dq1).append("<br/>");
        detail1.append("推荐数：").append(dq2).append("<br/>");
        detail1.append("推荐率：").append(dq).append("%").append("<br/>");
        detail2.append("南区").append("<br/>");
        detail2.append("计划数：").append(nq1).append("<br/>");
        detail2.append("推荐数：").append(nq2).append("<br/>");
        detail2.append("推荐率：").append(nq).append("%").append("<br/>");
        detail3.append("西区").append("<br/>");
        detail3.append("计划数：").append(xq1).append("<br/>");
        detail3.append("推荐数：").append(xq2).append("<br/>");
        detail3.append("推荐率：").append(xq).append("%").append("<br/>");
        detail4.append("北区").append("<br/>");
        detail4.append("计划数：").append(bq1).append("<br/>");
        detail4.append("推荐数：").append(bq2).append("<br/>");
        detail4.append("推荐率：").append(bq).append("%").append("<br/>");
        details.add(detail1);
        details.add(detail2);
        details.add(detail3);
        details.add(detail4);
        List<Object> datas = new ArrayList<>();

        Map<String, Object> line1 = new HashMap<>();
        Map<String, Object> bar1 = new HashMap<>();
        line1.put("name","推荐率%");
        line1.put("type","line");
        line1.put("data",counts);
        line1.put("yAxisIndex",1);

        bar1.put("data",finisheds);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        bar1.put("yAxisIndex",0);
        bar1.put("name","推荐数");
        datas.add(bar1);
        datas.add(line1);
        returnList.put("datas",datas);
        returnList.put("names",names);
        returnList.put("details",details);
        Map<String, String> parentMap = portalService.getParentId("XXZPXQZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","XXZPXQZBGL");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "店检报表" )
    @GetMapping("/projectTaskIssue")
    @ResponseBody
    public Map<String, Object> projectTaskIssue() {
        Map<String, Object> returnList = new HashMap<>();
        List<Map<String, Object>> list = reportService.projectTaskIssue();
        List<String> names = new ArrayList<>();
        List<String> values = new ArrayList<>();
        List<Integer> counts = new ArrayList<>();
        for (Map<String, Object> map : list) {
            StringBuilder str = new StringBuilder();
            String projectName = MapUtils.getString(map, "projectName");
            String djRound = MapUtils.getString(map, "djRound");
            String djDate = MapUtils.getString(map, "djDate");
            String shwcl = MapUtils.getString(map, "shwcl");
            String zfwcl = MapUtils.getString(map, "zfwcl");
            String name = MapUtils.getString(map, "djName");
            Integer count = MapUtils.getInteger(map, "count");
            Integer wcCount = MapUtils.getInteger(map, "wcCount");
            names.add(name);
            counts.add(wcCount);
            str.append("项目名称：").append(projectName).append("<br/>");
            str.append("轮次：").append(djRound).append("<br/>");
            str.append("店检时间：").append(djDate).append("<br/>");
            str.append("计划执行门店数：").append(count).append("<br/>");
            str.append("已执行门店数：").append(wcCount).append("<br/>");
            str.append("审核完成率：").append(shwcl).append("<br/>");
            str.append("走访完成率：").append(zfwcl);
            values.add(str.toString());
        }
        returnList.put("names",names);
        returnList.put("details",values);
        Map<String, Object> bar1 = new HashMap<>();
        bar1.put("data",counts);
        bar1.put("type","bar");
        bar1.put("stack","stack");
        returnList.put("data",bar1);

        Map<String, String> parentMap = portalService.getParentId("DJXQ");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","DJXQ");
        returnList.put("url",url);
        return returnList;
    }

    @ApiOperation(value = "地图报表" )
    @GetMapping("/projectMapData")
    @ResponseBody
    public Map<String, Object> projectMapData(String startDateStr,String endDateStr) throws ParseException {

        Map<String, Object> returnList = new HashMap<>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = null;
        Date endDate = null;
        if(StringUtil.isNotBlank(startDateStr)){
            startDate = formatter.parse(startDateStr);
        }
        if(StringUtil.isNotBlank(endDateStr)){
            endDate = formatter.parse(endDateStr);
        }
        List<Map<String, Object>> list = reportService.projectMapDataSum(startDate,endDate);
        Map<String, Object> chinaMap = createChinaMap();
        Map<String, Object> areData = new HashMap<>();
        areData.putAll(chinaMap);
        for (String key : chinaMap.keySet()) {
            for (Map<String, Object> map : list) {
                String province = MapUtils.getString(map,"province");
                if(province.contains(key)){
                    Integer count = MapUtils.getInteger(map,"count");
                    Integer areCount = MapUtils.getInteger(areData,key);
                    areData.put(key,areCount + count);
                }
            }
        }
        List<Map<String, Object>> areDatas = new ArrayList<>();
        for (String name : areData.keySet()) {
            Map<String, Object> map = new HashMap<>();
            Integer count = MapUtils.getInteger(areData,name);
            map.put("name",name);
            map.put("value",count);
            areDatas.add(map);
        }
        List<Map<String, Integer>> mapArea = new ArrayList<>();
        List<Map<String, Object>> settings = reportService.mapSetting();
        List<String> mapColor = new ArrayList<>();
        for (Map<String, Object> setting : settings) {
            Map<String, Integer> mapAreaMap = new HashMap<>();
            Integer startValue = MapUtils.getInteger(setting, "startValue");
            Integer endValue = MapUtils.getInteger(setting, "endValue");
            String color = MapUtils.getString(setting, "color");
            mapAreaMap.put("start",startValue);
            mapAreaMap.put("end",endValue);
            mapColor.add(color);
            mapArea.add(mapAreaMap);
        }
        returnList.put("mapData",areDatas);
        returnList.put("mapArea",mapArea);
        Collections.reverse(mapColor);
        returnList.put("mapColor", mapColor);

        areDatas.sort(Comparator.comparingInt(s -> MapUtils.getInteger(s,"value")));
        List<Map<String, Object>> pros = new ArrayList<>();
        for (int i = areDatas.size() - 1; i > areDatas.size() - 6; i--) {
            Map<String, Object> map = new HashMap<>();
            map.put("province",areDatas.get(i).get("name"));
            map.put("count",areDatas.get(i).get("value"));
            pros.add(map);
        }
        List<Map<String, Object>> citys = reportService.projectMapDataCityMax(startDate,endDate);
        Map<String, Object> proBar = new HashMap<>();
        proBar.put("data",pros);
        proBar.put("type","bar");
        proBar.put("stack","stack");
        returnList.put("proBar",proBar);
        Map<String, Object> cityBar = new HashMap<>();
        cityBar.put("data",citys);
        cityBar.put("type","bar");
        cityBar.put("stack","stack");
        returnList.put("cityBar",cityBar);

        Map<String, String> parentMap = portalService.getParentId("ZXZBGL");
        String parentId = parentMap.get("parentId");
        String url = sheetPowerUrl;
        url = url.replaceAll("P_A_R_E_N_T_I_D",parentId);
        url = url.replaceAll("C_O_D_E","ZXZBGL");
        returnList.put("url",url);
        return returnList;
    }

    private List<String> getYearMonth(){
        return Arrays.asList("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    }

    private List<String> getYearMonthInt(){
        return Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月");
    }

    private String getMonthValue(String month){
        if(month.equals("10月")||month.equals("11月")||month.equals("12月")){
            return month.replaceAll("月","");
        }else {
            return ("0").concat(month.replaceAll("月",""));
        }
    }

    private String getYearMonthValue(String month,String year){
        if(month.equals("10月")||month.equals("11月")||month.equals("12月")){
            return year.concat(month.replaceAll("月",""));
        }else {
            return year.concat("0").concat(month.replaceAll("月",""));
        }
    }

    private void setListValue(List<Map<String, Object>> list,Map<String, Object> map){
        Integer value = MapUtils.getInteger(map, "value");
        if(value==0){
            return;
        }else{
            list.add(map);
        }
    }

    private Map<String, Map<String, Object>> createPayPeopleCountingAvg(){
        Map<String, Map<String, Object>> returnMap = new HashMap<>();
        Map<String, Object> mapNow = new LinkedHashMap<>();
        Map<String, Object> mapBefor = new LinkedHashMap<>();
        Map<String, Object> pay = new LinkedHashMap<>();
        mapNow.put("岗位外包",0);
        mapNow.put("业务外包",0);
        mapNow.put("-",null);
        mapNow.put("人事外包",0);
        mapNow.put("--",null);
        mapNow.put("形式外包",0);
        mapNow.put("其他",0);

        mapBefor.put("岗位外包",0);
        mapBefor.put("业务外包",0);
        mapBefor.put("-",null);
        mapBefor.put("人事外包",0);
        mapBefor.put("--",null);
        mapBefor.put("形式外包",0);
        mapBefor.put("其他",0);

        pay.put("岗位外包","");
        pay.put("业务外包","");
        pay.put("-",null);
        pay.put("人事外包","");
        pay.put("--",null);
        pay.put("形式外包","");
        pay.put("其他","");
        returnMap.put("now",mapNow);
        returnMap.put("befor",mapBefor);
        returnMap.put("pay",pay);
        return returnMap;
    }

    private Map<String, Map<String, Object>> createPayPeopleCountingSum(){
        Map<String, Map<String, Object>> returnMap = new HashMap<>();
        Map<String, Object> mapNow = new LinkedHashMap<>();
        Map<String, Object> mapBefor = new LinkedHashMap<>();
        mapNow.put("项目用工",0);
        mapNow.put("门店兼职",0);

        mapBefor.put("项目用工",null);
        mapBefor.put("门店兼职",null);
        returnMap.put("now",mapNow);
        returnMap.put("befor",mapBefor);
        return returnMap;
    }

    private Map<String, Object> createChinaMap(){
        Map<String, Object> map = new HashMap<>();
        map.put("北京",0);
        map.put("天津",0);
        map.put("上海",0);
        map.put("重庆",0);
        map.put("河北",0);
        map.put("山西",0);
        map.put("辽宁",0);
        map.put("吉林",0);
        map.put("黑龙江",0);
        map.put("江苏",0);
        map.put("浙江",0);
        map.put("安徽",0);
        map.put("福建",0);
        map.put("江西",0);
        map.put("山东",0);
        map.put("河南",0);
        map.put("湖北",0);
        map.put("湖南",0);
        map.put("广东",0);
        map.put("海南",0);
        map.put("四川",0);
        map.put("贵州",0);
        map.put("云南",0);
        map.put("陕西",0);
        map.put("甘肃",0);
        map.put("青海",0);
        map.put("台湾",0);
        map.put("内蒙古",0);
        map.put("广西",0);
        map.put("西藏",0);
        map.put("宁夏",0);
        map.put("新疆",0);
        map.put("香港",0);
        map.put("澳门",0);
        return map;
    }

    private Date getFirstDate(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String nowDay = sdf.format(date);
        String firstDay = sdf.format(calendar.getTime());
        if(nowDay.equals(firstDay)){
            return date;
        }else{
            Integer week = getIntegerWeek(date);
            long diff = calendar.getTime().getTime() - date.getTime();
            long days = diff / (1000 * 60 * 60 * 24);
            if(week >= Math.abs(days)){
                return calendar.getTime();
            }else{
                calendar.setTime(date);
                calendar.add(Calendar.DAY_OF_YEAR, -week);
                return calendar.getTime();
            }
        }
    }

    private Date getLastDate(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        String nowDay = sdf.format(date);
        String lastDay = sdf.format(calendar.getTime());
        if(nowDay.equals(lastDay)){
            return date;
        }else{
            Integer week = 6 - getIntegerWeek(date);
            long diff = date.getTime() - calendar.getTime().getTime();
            long days = diff / (1000 * 60 * 60 * 24);
            if(week >= Math.abs(days)){
                return calendar.getTime();
            }else{
                calendar.setTime(date);
                calendar.add(Calendar.DAY_OF_YEAR, week);
                return calendar.getTime();
            }
        }
    }

    private Integer getIntegerWeek(Date today) {
        Integer week = 0;
        Calendar c = Calendar.getInstance();
        c.setTime(today);
        int weekday = c.get(Calendar.DAY_OF_WEEK);
        if (weekday == 1) {
            week = 6;
        } else if (weekday == 2) {
            week = 0;
        } else if (weekday == 3) {
            week = 1;
        } else if (weekday == 4) {
            week = 2;
        } else if (weekday == 5) {
            week = 3;
        } else if (weekday == 6) {
            week = 4;
        } else if (weekday == 7) {
            week = 5;
        }
        return week;
    }

    public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
        Map<K, V> result = new LinkedHashMap<>();
        Stream<Map.Entry<K, V>> st = map.entrySet().stream();
        st.sorted(Comparator.comparing(e -> e.getValue())).forEach(e -> result.put(e.getKey(), e.getValue()));
        return result;
    }
}
